package com.xufei.sliding_tab_demo;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import org.xufei.sliding_tab.SlidingTabLayout;

/**
 * @author 徐飞
 *         Date: 2016/01/24
 *         Time: 11:06
 */
public class TestAty extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
        viewPager.setAdapter(new TabViewPagerAdapter(getSupportFragmentManager(), this));
        SlidingTabLayout slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
        slidingTabLayout.setTabTitleTextSize(14);//标题字体大小
        slidingTabLayout.setTitleTextColor(Color.WHITE, 0xFFF8BBD0);//标题字体颜色
        slidingTabLayout.setTabStripWidth(110);//滑动条宽度
        slidingTabLayout.setSelectedIndicatorColors(Color.WHITE);//滑动条颜色
        slidingTabLayout.setDistributeEvenly(true); //均匀平铺选项卡
        slidingTabLayout.setViewPager(viewPager);//最后调用此方法

    }

    private class TabViewPagerAdapter extends FragmentPagerAdapter {

        private String[] mTabTitle = new String[]{"一啊", "二啊", "三啊", "四啊"};
        private Context mContext;
        private Fragment[] fragments = new Fragment[]{new TestFrg01(), new TestFrg01(), new TestFrg01(), new TestFrg01()};

        public TabViewPagerAdapter(FragmentManager fm, Context context) {
            super(fm);
            this.mContext = context;
        }

        @Override
        public Fragment getItem(int position) {
            return fragments[position];
        }

        @Override
        public int getCount() {
            return fragments.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTabTitle[position];
        }
    }

}
